package com.flow.demo.module.gd.controller.app.gift;

import cn.hutool.core.bean.BeanUtil;
import com.flow.demo.framework.common.pojo.CommonResult;
import com.flow.demo.framework.operatelog.core.annotations.OperateLog;
import com.flow.demo.framework.web.core.util.WebFrameworkUtils;
import com.flow.demo.module.gd.controller.app.gift.dto.GetVideoTimesDto;
import com.flow.demo.module.gd.controller.app.gift.dto.SaveAddressDto;
import com.flow.demo.module.gd.controller.app.gift.vo.SaveVideoTimeVo;
import com.flow.demo.module.gd.controller.app.user.dto.GetUserInfoDto;
import com.flow.demo.module.gd.controller.app.user.dto.UploadImgDto;
import com.flow.demo.module.gd.controller.app.user.vo.*;
import com.flow.demo.module.gd.dal.dataobject.gduser.GdUserDO;
import com.flow.demo.module.gd.dal.mysql.gduser.GdUserMapper;
import com.flow.demo.module.gd.dal.mysql.userVideoTime.UserVideoTimeMapper;
import com.flow.demo.module.gd.service.gduser.GdUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.flow.demo.framework.common.exception.enums.GlobalErrorCodeConstants.UNAUTHORIZED;
import static com.flow.demo.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.flow.demo.framework.common.pojo.CommonResult.success;
import static com.flow.demo.module.gd.enums.ErrorCodeConstants.GD_USER_NOT_EXISTS;

@Tag(name = "app - 用户")
@RestController
@Validated
public class AppGiftController {

    @Resource
    private GdUserService gdUserService;


    //获取视频查看时长
    @GetMapping("/videoTimes")
    @Operation(summary = "获取视频查看时长")
    public CommonResult<GetVideoTimesDto> getVideoTimes() {
        Long loginUserId = WebFrameworkUtils.getLoginUserId();
        return success( gdUserService.getVideoTimes(loginUserId));
    }

    //保存视频时长
    @PostMapping("/saveVideoTime")
    @Operation(summary = "保存视频时长")
    public CommonResult<Boolean> saveVideoTime(@Valid @RequestBody SaveVideoTimeVo vo) {
        Long loginUserId = WebFrameworkUtils.getLoginUserId();
        gdUserService.saveVideoTime(vo,loginUserId);
        return success(true);
    }

    //用户保存收获地址
    @PostMapping("/saveAddress")
    @Operation(summary = "用户保存收获地址")
    public CommonResult<Boolean> saveAddress(@Valid @RequestBody SaveAddressDto vo) {
        Long loginUserId = WebFrameworkUtils.getLoginUserId();
        gdUserService.saveAddress(vo,loginUserId);
        return success(true);
    }

//    //填写收获地址
//    @PostMapping("/sendCode")
//    @Operation(summary = "发送验证码")
//    public CommonResult<Boolean> sendCode(@Valid @RequestBody SendCodeVo vo) {
//        gdUserService.sendCode(vo);
//        return success(true);
//    }


//
//    //查看是否拥有抽奖机会
//    @GetMapping("/getUserInfo")
//    @Operation(summary = "获得用户信息")
//    public CommonResult<GetUserInfoDto> getUserInfo() {
//        Long loginUserId = WebFrameworkUtils.getLoginUserId();
//        GdUserDO gdUserDO = gdUserMapper.selectOne(GdUserDO::getId, loginUserId);
//        if (gdUserDO == null)
//            throw exception(GD_USER_NOT_EXISTS);
//        return success( BeanUtil.toBean(gdUserDO,GetUserInfoDto.class));
//    }
//
//


//
//
//    //点击抽奖
//    @GetMapping("/getUserInfo")
//    @Operation(summary = "获得用户信息")
//    public CommonResult<GetUserInfoDto> getUserInfo() {
//        Long loginUserId = WebFrameworkUtils.getLoginUserId();
//        GdUserDO gdUserDO = gdUserMapper.selectOne(GdUserDO::getId, loginUserId);
//        if (gdUserDO == null)
//            throw exception(GD_USER_NOT_EXISTS);
//        return success( BeanUtil.toBean(gdUserDO,GetUserInfoDto.class));
//    }

}
